const tokens = {
	admin: {
		token: "admin"
	},
	editor: {
		token: "editor"
	}
};

const users = {
	admin: {
		roles: ["admin"],
		introduction: "I am a super administrator",
		avatar: "https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif",
		name: "Super Admin"
	},
	editor: {
		roles: ["editor"],
		introduction: "I am an editor",
		avatar: "https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif",
		name: "Normal Editor"
	}
};

module.exports = [
	// user login
	{
		url: "/mock-data/user/login",
		type: "post",
		response: config => {
			const { username } = config.body;
			const token = tokens[username];

			// mock error
			if (!token) {
				return {
					code: 60204,
					message: "用户名出错"
				};
			}

			return {
				code: 200,
				data: token
			};
		}
	},

	// get user info
	{
		url: "/mock-data/user/getUserInfo",
		type: "get",
		response: config => {
			const { token } = config.query;
			const info = users[token];

			// mock error
			if (!info) {
				return {
					code: 50008,
					message: "获取用户信息失败,无法获取当前用户详情"
				};
			}

			return {
				code: 200,
				data: info
			};
		}
	},

	// user logout
	{
		url: "/mock-data/user/logout",
		type: "post",
		response: _ => {
			return {
				code: 200,
				data: "success"
			};
		}
	}
];
